package dbHandle

import (
	"fmt"
	"io"
	"net/http"
	"net/url"
	"utilsx/tools/httpUtils"
)

var (
	//SteamAppDetails = "https://store.steampowered.com/api/appdetails/?appids="
	SteamAppDetails, _ = url.Parse("https://store.steampowered.com/api/appdetails/")
)

func modifyRequest(req *http.Request) {
	req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36")
	req.Header.Add("Accept", "application/json, text/javascript")
	req.Header.Add("Origin", "https://developer.music.163.com")
	req.Header.Add("Referer", "https://developer.music.163.com/")
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Connection", "keep-alive")
}
func RequestBodySingle(client *http.Client, appid string) ([]byte, error) {
	values := make(url.Values)
	values.Set("appids", appid)
	SteamAppDetails.RawQuery = values.Encode()
	req := httpUtils.CreateReq(SteamAppDetails.String(), http.MethodGet, nil, func(req *http.Request) {
		req.Header.Add("Accept", "*/*")
		req.Header.Add("Host", "store.steampowered.com")
		req.Header.Add("Connection", "keep-alive")
	})
	modifyRequest(req)
	resp, err := client.Do(req)
	if err != nil {
		panic(resp.StatusCode)
		return nil, err
	}
	defer resp.Body.Close()
	respBytes, err := io.ReadAll(resp.Body)
	if err != nil {
		err = fmt.Errorf("read response data failed: %s", err.Error())
		return nil, err
	}

	return respBytes, nil
}
